CONTENTS | INDEX | PREV | NEXT
fgetpos
NAME
fgetpos - get current file position
SYNOPSIS
#include <stdio.h>
int error = fgetpos(fp, &pos);
fpos_t pos;
FUNCTION
fgetpos() returns the current seek position and is roughly equivalent
to ftell(). fgetpos() is a new ANSI call to better support C
compilers that use 16 bit integers. DICE uses 32 bit integers so
fgetpos() is not so useful.
fgetpos() takes a file pointer and the address of a fpos_t type
(a long). It fills the fpos_t variable with the current file
position and returns 0 if all went well, non-zero if an error
occured.
NOTE
refer to the file_pointer manual page for general information
EXAMPLE
/*
* return the length of the file specified on the command line.
* P.S. it is more efficient to use open/lseek/close instead
* of fopen/fseek/fgetpos/fclose
*/
#include <stdio.h>
main(ac, av)
int ac;
char **av;
{
FILE *fp;
fpos_t off;
if (ac == 1) {
puts("Expected a filename argument");
exit(1);
}
fp = fopen(av[1], "r");
if (fp == NULL) {
printf("Unable to open %sn", av[1]);
exit(10);
}
fseek(fp, 0L, SEEK_END);
if (fgetpos(fp, &off)) {
puts("Error getting file position");
exit(20);
}
fclose(fp);
printf("File %s is %d bytesn", av[1], off);
return(0);
}
INPUTS
FILE *fp; file pointer
fpos_t *pos; pointer to an fpos_t type that the position is loaded into.
RESULTS
int error; 0 if no error, non-zero on error
SEE ALSO
ftell, rewind, fseek, rewind